package com.alibaba.config.controller;


import com.alibaba.config.config.ConfigBean;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@RestController
@RefreshScope
public class TestController {

    @Resource
    private ConfigBean configBean;


    @Value("${user.name:defaultName}")
     String name;
    @Value("${user.age:10}")
     Integer age;
    private static  volatile  boolean showFlag=false;

    @RequestMapping(value="/showConfig",method= RequestMethod.GET)
    public Object showConfig() throws InterruptedException {
        TestController.showFlag=!TestController.showFlag;
        while (TestController.showFlag){
            System.out.println("JSON.toJSONString() = " + JSON.toJSONString(configBean));
//            System.out.println("JSON. = " + JSON.toJSONString(configBean.name));
            System.out.println("JSON.this feids = " + name+"age"+age);
            TimeUnit.SECONDS.sleep(2);
        }
        return "show end!";
    }
}
